var roomAppservice = require('../../data/AppService/roomAppService.js');
var buyerAppService = require('../../data/AppService/buyerAppService.js');
var commonData = require("../../data/Common/commonData.js");
const app = getApp();
// pages/room/list.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    /**
     * 房间列表数据
     */
    RoomInfoList: [],

    avatarUrl: '/images/user.png',
    Phone: "",
    customName: '',
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    this._getRoomInfoListDatas(this.data.Phone);
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    if(options.phone){
      wx.setStorageSync(app.cacheKey.userInfo_phone, options.phone);
    }
    var that = this;
    var avatarUrl = wx.getStorageSync(app.cacheKey.userInfo_avatarUrl) || '/images/user.png';
    var userPhone = wx.getStorageSync(app.cacheKey.userInfo_phone) || '15100000086';
    that.setData({
      avatarUrl: avatarUrl,
      Phone: userPhone
    })
  },
  /**
   * 获取房间信息
   */
  _getRoomInfoListDatas: function(Phone) {
    var me = this;    
    buyerAppService.GetCstInfo(Phone, function(buyerInfos) {
      if (buyerInfos && buyerInfos.data && buyerInfos.data.success) {
        me.setData({
          customName: buyerInfos.data.data.CstName
        });
        var cstGuid = buyerInfos.data.data.BuyerGUID;
        roomAppservice.GetRoomList(cstGuid, function(roomInfos) {
          var roomIn = [];
          for (var i = 0; i < roomInfos.data.length; i++) {
            roomIn.push({
              RoomGUID: roomInfos.data[i].RoomGUID,
              auditstatus: roomInfos.data[i].DataAuditStatusEnum,
              roomname: roomInfos.data[i].ShortRoomInfo,
              zygwName: roomInfos.data[i].Zygw,
              zygwTel: ""
            })
          }
          me.setData({
            RoomDataList: roomIn
          });
        });
      }
    })
  }
})